The present invention is generally directed to database systems, and more particularly to an interface for database systems that facilitates the interaction of external application programs with a database system.
In a number of different situations, it is useful for an application program to be able to retrieve data from a database, and/or update data in the database. Currently, many such programs are written in an object-oriented programming language, such as Java, which sends messages from one object to another to effect operations. In contrast, most database programs are written in other types of programming languages, and therefore are not adapted to respond to the messages sent by object-oriented programs. The database programs employ commands that have a predetermined structure which must be utilized to manipulate data in the database. One particularly prominent example of a programming language which has such a requirement is the Structured Query Language (SQL) for relational databases that are comprised of tables.
In order for an application program to be able to access data in a database, therefore, it is necessary for the program to include functionality which enables it to generate commands that are appropriate to the database being accessed. Hence, if a SQL database program is to be accessed, the application program must be capable of generating SQL data manipulation statements to send to the database. Typically, this functionality is provided by directly coding it into the application program itself. However, such an approach is undesirable for a number of reasons. First, it requires the programmer who is writing the application program to have familiarity with the database programming language, such as SQL. In addition, the programmer must have knowledge about the structure of the particular database to be accessed, e.g how the data is arranged in the various tables. This can impose a significant burden on the development of the application program since, if the programmer is not versed in the database programming language, or familiar with the structure of the database, errors are likely to arise, resulting in a considerable debugging effort.
Secondly, if the structure of the database is changed, the application program may no longer be able to access the data. For instance, one table in the database may be split into two or more tables. If the application has been coded to address the prior single table, it will not be able to generate the appropriate commands to access the two new tables. In such a case, it becomes necessary to rewrite the application program to enable it to work with the restructured database. It can be seen that such an approach is unacceptable, particularly if the database is one which is susceptible to having its structure modified from time to time to accommodate new data.
It is desirable, therefore, to provide a system and method for automatically generating database statements from messages generated by application programs, which avoids the need to have database functionality hard-coded into the application program itself. It is further desirable to implement such a system and method in a manner which eliminates reliance by the application program on the structure of the database, thereby enabling the database to be modified without requiring changes in the application program.
In accordance with the present invention, an interface provides a level of abstraction between the structure of a database system and application programs which access that system. The database system is represented by a model comprised of objects which correspond to the components of the database system, e.g. tables and fields within the tables. An object at a higher level encapsulates information contained in these other objects regarding the structure of the database. Whenever an application program requires access to the database, it sends a message to the higher level encapsulation object. This object then presents the message to appropriate ones of the lower-level objects. By isolating the existence of the lower level objects from the application programs through the higher-level encapsulation object, changes can be made to the structure of the database without affecting the operation of the application programs.
As a further feature of the invention, the lower-level objects implement methods which automatically generate appropriate database commands. When the encapsulation object receives a call from an application program requesting data in the database, it instructs table objects to obtain the required data. In response, the table objects invoke field objects to identify how to represent data in each of the database fields to which they correspond. The table object concatenates the responses received from each of the field objects to construct a command that is presented to the database to retrieve the desired data.